#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int g, n, m;
vector < vec > G[N];
ll dis[N];

int main() {
#ifndef ONLINE_JUDGE
	//freopen("1.in", "r", stdin);
#endif
	g = in, n = in, m = in;
	if(m) {
		puts("NO 2");
		puts("NO 4");
		puts("NO 9");
		puts("YES");
		return 0;
	}
	rep(i, 1, n) {
		int a = in, k = in; vec pot;
		while(k--) pot.eb(in);
		G[a].eb(pot);
	} memset(dis, -1, sizeof dis); dis[0] = dis[1] = 1;
	bool fl = true;
	while(fl) {
		fl = false;
		rep(i, 2, g - 1) {
			for(auto v : G[i]) {
				ll res = 0; bool tfl = 0;
				for(auto y : v) { 
					if(dis[y] == -1) { tfl = true; break; }
					res += dis[y];
				}
				if(tfl) continue;
				if(dis[i] == -1) dis[i] = res, fl = true;
				else if(dis[i] > res) dis[i] = res, fl = true;
			}
		}
	} rep(i, 2, g - 1) if(dis[i] == -1) puts("YES"); else printf("NO %lld\n", dis[i]);
	return 0;
}
